package com.tiantianyuegou.util;

import android.app.Dialog;
import android.content.Context;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.tiantianyuegou.R;


/**
 * 自定义加载框
 * Created by huyang on 2016/1/15 0015.
 */
public class LoadingDialog extends Dialog {

    private ProgressBar img;
    private TextView txt;

    public LoadingDialog(Context context) {
        super(context, R.style.LoadingDialog);


        View view= View.inflate(context, R.layout.dialog_loading, null);
        img=(ProgressBar) view.findViewById(R.id.progress_dialog_img);
        txt = (TextView) view.findViewById(R.id.progress_dialog_txt);
        getWindow().setBackgroundDrawableResource(R.drawable.dialog_loading_bg);
        //dialog添加视图
        setContentView(view);
        this.setCancelable(false);
    }

    /**
     * 对话框设置内容
     * @param msg
     */
    public void setMsg(String msg){
        txt.setText(msg);
    }
    /**
     * 设置对话框背景
     * @param msgId
     */
    public void setMsg(int msgId){
        txt.setText(msgId);
    }
    /**
     * 显示对话框
     */
    public void showDialog(){
        this.show();
    }
    /**
     * 关闭对话框
     */
    public void closeProgersssDialog(){
        this.dismiss();
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            // 按下了键盘上返回按钮
            this.hide();
            return true;
        }
        return false;
    }

}
